#ifndef SERVER_HH
# define SERVER_HH

# include <network/network-manager.hh>

using boost::asio::ip::tcp;

# include "display/object.hh"
# include "request/request-handler-client.hh"
# include "request/request-creator-client.hh"

# include <tbb/concurrent_hash_map.h>

# include <boost/shared_ptr.hpp>

class Map;
class Chat;

class Server
{
public:
  Server (const std::string& server, const std::string& port);
  ~Server ();

  bool connect (const std::string& logpwd);
  void build_map ();
  void build_map_fps ();

  const Map* map () const;
  const tbb::concurrent_hash_map<int, boost::shared_ptr<Object> >* objmap () const { return &objmap_; }
  tbb::concurrent_hash_map<int, boost::shared_ptr<Displayable> >* disp () { return &disp_; }

  NetworkManager* nm () { return &nm_; }

  void run ();

  void add_obj (boost::shared_ptr<Object> o);

  void stop ();

  bool reset_selection () const { return reset_selection_; }

protected:
  bool run_;
  boost::asio::io_service ios_;
  NetworkManager nm_;

  tbb::concurrent_hash_map<int, boost::shared_ptr<Object> > objmap_;
  tbb::concurrent_hash_map<int, boost::shared_ptr<Displayable> > disp_;

  RequestHandlerClient rh_;

  Map* rts_map_;
  Map* fps_map_;

  bool reset_selection_;
};

#endif ///!SERVER_HH
